<?php
/**
 * User: dimka3210
 * Date: 19.11.13
 * Time: 20:45
 */
include_once('../core/autoload.php');
?>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/static/css/my.css">
</head>
<body>
<?php
$user = new User();

if (!$user->checkAdminRight()) {
    ?>
    <h3>Введите данные для входа</h3>
    <form method="post" enctype="application/x-www-form-urlencoded">
        <input type="text" name="username">
        <input type="password" name="pass">
        <input type="submit">
    </form>
<?php
} else {
    $limit = CNF::$params['paging']['limit'];
    $offset = (isset($_GET['page'])) ? (intval($_GET['page']) - 1) * $limit : 0;
    $rows = Storage::getInstance()->getRows($limit, $offset, false);
    ?>
    <a href="/admin/edit.php">Add news</a>
    <table class="content">
        <tr>
            <th>id</th>
            <th>Title</th>
            <th>Text</th>
            <th>Create date</th>
            <th>Update date</th>
            <th>Actions</th>
        </tr>
        <?php foreach ($rows as $row) { ?>
            <tr>
                <td><?= $row['id'] ?></td>
                <td><?= $row['title'] ?></td>
                <td><?= $row['text'] ?></td>
                <td><?= $row['create_date'] ?></td>
                <td><?= $row['modify_date'] ?></td>
                <td>
                    <a href="/admin/edit.php?id=<?= $row['id'] ?>">Edit</a>
                    <a href="/admin/delete.php?id=<?= $row['id'] ?>">Delete</a>
                </td>
            </tr>
        <?php } ?>
    </table>
<?php } ?>
</body>
</html>